package com.gogant.spider.http;

import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.gogant.spider.core.Request;

public class HttpRequest extends Request {
	public enum Method {
		GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE
	}

	private boolean enableJavascript;
	private Method method = null;
	private Map<String, String> paramMap = new HashMap<String, String>();

	public HttpRequest(URL url) {
		super(url);
	}

	public boolean isEnableJavascript() {
		return enableJavascript;
	}

	public void setEnableJavascript(boolean enableJavascript) {
		this.enableJavascript = enableJavascript;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	public void putParam(String key, String value) {
		if (key == null) {
			return;
		}
		paramMap.put(key, value == null ? "" : value);
	}

	public String getParam(String key) {
		return paramMap.get(key);
	}

	public String removeParam(String key) {
		return paramMap.remove(key);
	}

	public Set<String> paramKeySet() {
		return new HashSet<String>(paramMap.keySet());
	}

	public void setCookie(String cookies) {
		putHeader("Cookie", cookies);
	}
}
